package kr.hkit.powerjava.chapter26;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.CardLayout;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.util.Scanner;

import kr.hkit.powerjava.chapter26.common.ConnectionFactory;
import kr.hkit.powerjava.chapter26.common.DbUtil;
import kr.hkit.powerjava.chapter26.dto.Department;
import kr.hkit.powerjava.chapter26.dto.Employee;
import kr.hkit.powerjava.chapter26.service.AbsService;
import kr.hkit.powerjava.chapter26.service.DepartmentService;
import kr.hkit.powerjava.chapter26.service.EmployeeService;

public class TestMain extends JFrame implements ActionListener {

	private JPanel contentPane;
	private JPanel panel;
	private JButton btnDept;
	private JButton btnEmp;

	Scanner sc = new Scanner(System.in);
	Connection connection = ConnectionFactory.getConnection();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestMain frame = new TestMain();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TestMain() {
		initialize();
	}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		
		btnEmp = new JButton("사원관리");
		btnEmp.addActionListener(this);
		panel.add(btnEmp);
		
		btnDept = new JButton("부서관리");
		btnDept.addActionListener(this);
		panel.add(btnDept);
		
		pack();
	}
	

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("사원관리")) {
				AbsService<Employee> empSvc = new EmployeeService(sc,
						connection);
				empSvc.prnMenu();
		} else {
				AbsService<Department> deptSvc = new DepartmentService(sc,
						connection);
				deptSvc.prnMenu();
		}
		DbUtil.close(connection);
	}
}
